<template>
    <div class="dataReport_container">
        <el-row type="flex" align="middle">
            <el-col :span="1" :offset="10">
                <i class="el-icon-data-analysis"></i>
            </el-col>
            <el-col :span="3">
                <h1>数据报表</h1>
            </el-col>
        </el-row>
        <div id="reportChart" v-if="checkReport"></div>
        <el-row v-else>
            <el-col>
                <el-empty
                    description="暂无数据报表"
                    image="https://www.gstatic.com/android/keyboard/emojikitchen/20201001/u1f422/u1f422_u1f4f0.png"
                >
                </el-empty>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import * as echarts from 'echarts';
export default({
    name:'datareports',
    async mounted(){
        var myChart = echarts.init(document.getElementById('reportChart'));
        const { data: res} = await this.$http.get('reports/type/1');
        if(res.meta.status == 200){
            this.checkReport = true;
            // const finalResult = Object.assign(this.options,res.data);
            const finalResult = {...this.options,...res.data}
            finalResult.xAxis[0].boundaryGap = false;
            myChart.setOption(finalResult);
        }else {
            this.checkReport = false;
            return this.$message(
                {
                    center:true,
                    showClose: true,
                    type: 'error',
                    duration:2000,
                    message: '获取数据报表失败！'
                }
            )
        }
    },
    data(){
        return{
            options: {
                title: {
                    text: '用户来源'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                    type: 'cross',
                    label: {
                        backgroundColor: '#E9EEF3'
                    }
                    }
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: [
                    {
                    boundaryGap: false
                    }
                ],
                yAxis: [
                    {
                    type: 'value'
                    }
                ]
            },
            checkReport: true,
        }
    }
})
</script>

<style lang="less" scoped>
    .dataReport_container{
        width: 80vw;
        text-align: center;
        background-color: #fff;
        padding: 30px 8px;
        margin:4vh auto;
        border-radius: 15px;
        box-shadow: 0 1px 15px #cbcbcb;
        h1{
            color: #3a2c3b;
            letter-spacing: 6px;
        }
        #reportChart{
            width: 70vw;
            height:52vh;
            margin:20px auto 0 auto;
        }
    }
</style>